package com.noahplat.datapro.mapper;

import com.noahplat.datapro.pojo.Heart;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.Date;
import java.util.List;

/**
 * @InterfaceName: HeartProMapper
 * @Description: 可穿戴设备心率数据mapper
 * @Author 李景星
 * @Date 2021/3/4
 * @Version 1.0
 */
public interface HeartProMapper extends Mapper<Heart> {

    /**
     * 查询设备当前心率值
     * @param imei
     * @return
     */
    @Select("select LAST_ROW(heart) as heart, ts as ts from heart_${imei}")
    public Heart getNowHeart(@Param("imei") String imei);

    /**
     * 获取设备历史心率
     * @param imei
     * @param startDate
     * @param endDate
     * @return
     */
    @Select("select heart as heart, ts as ts from heart_${imei} where ts >= #{startDate} and ts < #{endDate} order by ts desc")
    public List<Heart> getHisHeart(@Param("imei") String imei, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
}
